package com.itheima.springbootwebtlias.mapper;

import com.itheima.springbootwebtlias.pojo.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 部门持久层接口：处理部门相关的持久层操作
 */
@Mapper
public interface DeptMapper {

    //查询部门列表
    /*@Results({
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "updateTime", column = "update_time")
    })*/
    //@Select("select id, name, create_time /*as createTime*/, update_time /*as updateTime*/ from dept")
    //List<Dept> selectAll();
    @Select("select * from dept")
    List<Dept> selectAll();

    //删除部门
    @Delete("delete from dept where id = #{id}")
    void removeById(Integer id);

    //新增部门
    @Insert("insert into dept(id, name, create_time, update_time) " +
            "values (null,#{name},#{createTime},#{updateTime})")
    void saveDept(Dept dept);

    //根据id查询部门
    @Select("select * from dept where id = #{id};")
    Dept selectById(int id);

    //更新部门
    @Update("update dept set name = #{name}, update_time=#{updateTime} where id = #{id};")
    void update(Dept dept);
}
